package com.bjwl.web.contrlller.branchstore;

import com.bjwl.pojo.Bsadmin;
import com.bjwl.pojo.ServiceSource;
import com.bjwl.pojo.vo.BasicQueryVo;
import com.bjwl.service.SourceService;
import com.bjwl.utils.PageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

/**
 * @Author: dzx
 * @Date:Create：in 2020/5/11 9:18
 * @Description:
 * @Modified By：
 * @Version: 1.0
 */
@Controller
@RequestMapping("/bsSource")
public class SourceControllerabc {


    @Autowired
    private SourceService sourceService;

    @RequestMapping("/findAllSource")
    public String sourceList(BasicQueryVo vo, Model model){
        PageBean<ServiceSource> pageBean = sourceService.sourceList(vo);
        model.addAttribute("pageBean",pageBean);
       return "branch_oa/source-list";
    }

    @RequestMapping("/addSource")
    public @ResponseBody
    boolean addServiceSource(@RequestBody ServiceSource serviceSource , HttpSession httpSession){
        Bsadmin bsadmin = (Bsadmin) httpSession.getAttribute("bsadmin1");
        serviceSource.setBsid(bsadmin.getBsid());
        return sourceService.addServiceSource(serviceSource);
    }

    /**
     * 修改前回显
     * @param
     * @param model
     * @return
     */
    @RequestMapping("/editStartSource")
    public String editStart(Integer id, Model model){
        model.addAttribute("ServiceSource",sourceService.editStart(id));
        return "branch_oa/source-edit";
    }

    /**
     * 修改
     * @param
     * @param
     * @return
     */
    @RequestMapping("/editEndSource")
    public @ResponseBody
    boolean updateServiceSource(@RequestBody ServiceSource serviceSource){

        return sourceService.updateServiceSource(serviceSource);
    }

    @RequestMapping("/deleteServiceSource")
    public @ResponseBody
    boolean deleteServiceSource(@RequestBody Integer id){

        return sourceService.deleteServiceSource(id);
    }


}
